#define _CRT_SECURE_NO_WARNINGS

#include"c1.h"
#define MAXQSIZE 100

//typedef struct
//{
//	int *base;
//	int *top;
//	int stacksize; 
//}SqStack;
//Status InitStack(SqStack *S);
//Status GetTop(SqStack S,int *e);
//Status Push(SqStack *S,int e);
//Status Pop(SqStack *S,int *e);
//Boolean StackEmpty(SqStack S);
//int StackLength(SqStack S);
//Status ClearStack(SqStack *S);
//Status DestoryStack(SqStack *S);


Status InitStack(SqStack* S)
{
	S->base = (Status*)malloc(100 * sizeof(Status));
	if (!S->base)
		OVERFLOW;
	S->top = S->base;
	S->stacksize = 100;
	return OK;
}

Status GetTop(SqStack S, Status* e)
{
	if (S.top == S.base)
		return ERROR;
	*e = *(S.top - 1);
	return OK;
}

Status Push(SqStack* S, Status e)
{
	//if (S->top == S->base)
	//	return ERROR;
	*(S->top++) = e;
	return OK;
}
Status Pop(SqStack* S, Status* e)
{
	if (S->top == S->base)
		return ERROR;
	*e = *(--S->top);
	return OK;
}
Boolean StackEmpty(SqStack S)
{
	if (S.top == S.base)
		return 1;
	else
		return 0;
}
int StackLength(SqStack S)
{
	return *(S.top) - *(S.base);
}
Status ClearStack(SqStack* S)
{
	if (S->base)
		S->top = S->base;
	return OK;
}
Status DestoryStack(SqStack* S)
{
	if (S->base)
	{
		free(S->base);
		S->stacksize = 0;
		S->base = S->top = NULL;
	}
	return OK;
}

